package cn.com.zpark.session;

import cn.com.zpark.session.bean.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @PackageName: cn.com.zpark.session
 * @ClassName: SessionDemo06
 * @Description:
 * @author: RZS
 * @date: 2021/11/15  16:03
 */
@WebServlet("/sd6.do")
public class SessionDemo06 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取session绑定的user数据
        // 获取session对象
        HttpSession session = request.getSession();
        User user = (User)session.getAttribute("user");
        System.out.println(user.toString());

        // 响应到浏览器
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("<h1>"+user.toString()+"</h1>");
    }
}
